package cn.liulin.spring_boot_study.pojo;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * cn.liulin.spring_boot_study.pojo$
 *
 * @author ll
 * @date 2021-10-22 13:59:07
 **/
//@Component
public class BussinessMoreThanPerson implements Person, BeanNameAware, BeanFactoryAware,
        ApplicationContextAware, InitializingBean, DisposableBean {
    private Animal animal;

    public BussinessMoreThanPerson(Animal animal) {
        this.animal = animal;
    }

    @Override
    public void service() {
        animal.use();
    }

    @Override
    @Autowired
    public void setAnimal(Animal animal) {
        System.out.println("延迟依赖注入");
        this.animal = animal;
    }

    /**
     * BeanNameAware的实现方法
     * @author ll
     * @date 2021-10-22 13:59:53
     * @param s
     * @return void
     **/
    @Override
    public void setBeanName(String s) {
        System.out.println("【" + this.getClass().getSimpleName() + "】调用BeanNameAware的setBeanName");
    }

    /**
     * BeanFactoryAware的实现方法
     * @author ll
     * @date 2021-10-22 14:05:49
     * @param beanFactory
     * @return void
     **/
    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("【" + this.getClass().getSimpleName() + "】调用BeanFactoryAware的setBeanFactory");
    }

    /**
     * ApplicationContextAware的实现方法
     * @author ll
     * @date 2021-10-22 14:06:52
     * @param applicationContext
     * @return void
     **/
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("【" + this.getClass().getSimpleName() + "】调用ApplicationContextAware的setApplicationContext");
    }

    /**
     * InitializingBean的实现方法
     * @author ll
     * @date 2021-10-22 14:08:59
     * @return void
     **/
    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("【" + this.getClass().getSimpleName() + "】调用InitializingBean的afterPropertiesSet");
    }

    /**
     * DisposableBean的实现方法
     * @author ll
     * @date 2021-10-22 14:10:12
     * @return void
     **/
    @Override
    public void destroy() throws Exception {
        System.out.println("【" + this.getClass().getSimpleName() + "】调用DisposableBean的destroy");
    }

    @PostConstruct
    public void init() {
        System.out.println("【" + this.getClass().getSimpleName() + "】调用注解PostConstruct定义的自定义初始化方法");
    }

    @PreDestroy
    public void destroy1() {
        System.out.println("【" + this.getClass().getSimpleName() + "】调用注解PreDestroy定义的自定义销毁方法");
    }
}
